package cn.edu.web.原始Servlet;

import cn.edu.pojo.Brand;
import cn.edu.service.BrandService;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.List;

/**
 * @author Davey chan
 */

//@WebServlet("/addServlet")
public class AddServlet extends HttpServlet {
    private BrandService brandService = new BrandService();
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//获取请求体的数据
        BufferedReader br=request.getReader();
        String s = br.readLine();
//        将JSON字符串转成JAVA对象
        Brand brand = JSON.parseObject(s, Brand.class);
//        调用service的添加
        brandService.add(brand);
//        响应成功的标识
        response.getWriter().write("success");


    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }


}
